<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('消息模板列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label>模板代码：</label>
                                <input type="text" name="templateCode"/>
                            </li>
                            <li>
                                <label>模板名称：</label>
                                <input type="text" name="templateName"/>
                            </li>
                            <li>
                                <label>模板类型：</label>
                                <select name="templateType">
                                    <option value="">所有</option>
                                    <option value="0">系统消息</option>
                                    <option value="1">短信消息</option>
                                    <option value="2">微信消息</option>
                                </select>
                            </li>
                            <li>
                                <label>状态：</label>
                                <select name="status">
                                    <option value="">所有</option>
                                    <option value="0">正常</option>
                                    <option value="1">停用</option>
                                </select>
                            </li>
                            <li class="select-time">
                                <label>创建时间：</label>
                                <input type="text" class="time-input" id="startTime" placeholder="开始时间" name="params[beginTime]"/>
                                <span>-</span>
                                <input type="text" class="time-input" id="endTime" placeholder="结束时间" name="params[endTime]"/>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="business:template:add">
                    <i class="fa fa-plus"></i> 添加
                </a>
                <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="business:template:edit">
                    <i class="fa fa-edit"></i> 修改
                </a>
                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="business:template:remove">
                    <i class="fa fa-remove"></i> 删除
                </a>
                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="business:template:export">
                    <i class="fa fa-download"></i> 导出
                </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('business:template:edit')}]];
        var removeFlag = [[${@permission.hasPermi('business:template:remove')}]];
        var detailFlag = [[${@permission.hasPermi('business:template:detail')}]];
        var templateTypeData = [
            {code: "0", text: "系统消息"},
            {code: "1", text: "短信消息"},
            {code: "2", text: "微信消息"}
        ];
        var statusData = [
            {code: "0", text: "正常"},
            {code: "1", text: "停用"}
        ];
        
        var prefix = ctx + "business/template";

        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                modalName: "消息模板",
                columns: [{
                    checkbox: true
                },
                {
                    field: 'templateId',
                    title: '模板ID'
                },
                {
                    field: 'templateCode',
                    title: '模板代码'
                },
                {
                    field: 'templateName',
                    title: '模板名称'
                },
                {
                    field: 'templateContent',
                    title: '模板内容',
                    formatter: function(value, row, index) {
                        if (value && value.length > 30) {
                            return '<span title="' + value + '">' + value.substring(0, 30) + '...</span>';
                        }
                        return value;
                    }
                },
                {
                    field: 'templateType',
                    title: '模板类型',
                    formatter: function(value, row, index) {
                        for(var i=0; i<templateTypeData.length; i++) {
                            if(value == templateTypeData[i].code) {
                                return templateTypeData[i].text;
                            }
                        }
                        return value;
                    }
                },
                {
                    field: 'status',
                    title: '状态',
                    formatter: function(value, row, index) {
                        return $.table.selectDictLabel(statusData, value);
                    }
                },
                {
                    field: 'createTime',
                    title: '创建时间'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.templateId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-info btn-xs ' + detailFlag + '" href="javascript:void(0)" onclick="$.operate.detail(\'' + row.templateId + '\')"><i class="fa fa-search"></i>详情</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.templateId + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });
        
        /* 模板状态修改 */
        function changeStatus(templateId, status) {
            var newStatus = (status == 0) ? 1 : 0;
            var statusText = (newStatus == 0) ? "正常" : "停用";
            $.modal.confirm("确认要" + statusText + "该模板吗?", function() {
                $.operate.post(prefix + "/changeStatus", { "templateId": templateId, "status": newStatus });
            });
        }
    </script>
</body>
</html> 